﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Maticsoft.Common;

namespace MidSoft.Sys.Department
{
    public partial class Modify : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int DepartMentId = ChinaSoft.Common.Input.SetInt(Request.Params["id"]);
                    ShowInfo(DepartMentId);
                }
            }
        }
        private void ShowInfo(int DepartMentId)
        {
            ChinaSoft.BLL.Common.Bind bllbind = new ChinaSoft.BLL.Common.Bind();
            System.Data.DataSet ds = bllbind.GetDataSet("DepartMentName,OrganizeName,DepartMentNumber", "V_DepartmentList", "DepartMentId=" + DepartMentId);
            if (ds != null && ds.Tables.Count > 0)
            {
                this.lblOrganizeName.Text = ds.Tables[0].Rows[0]["OrganizeName"].ToString();
                this.tbDepartmentName.Text = ds.Tables[0].Rows[0]["DepartMentName"].ToString();
                this.tbDepartMentNumber.Text = ds.Tables[0].Rows[0]["DepartMentNumber"].ToString();
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";
            if (this.tbDepartmentName.Text.Trim().Length == 0)
            {
                strErr += "部门名称不能为空！\\n";
            }
            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int DepartMentId = ChinaSoft.Common.Input.SetInt(Request.Params["id"]);
            string DepartmentName = this.tbDepartmentName.Text;
            string DepartMentNumber = this.tbDepartMentNumber.Text;
            #region 修改
            ChinaSoft.BLL.BLL_tb_MidSoft_DepartMent bll = new ChinaSoft.BLL.BLL_tb_MidSoft_DepartMent();
            ChinaSoft.Model.Model_tb_MidSoft_DepartMent model = bll.GetModel(DepartMentId);
            model.DepartMentName = DepartmentName;
            model.DepartMentNumber = DepartMentNumber;
            bll.Update(model);
            #endregion

            #region 添加日志
            ChinaSoft.Model.Model_tb_MidSoft_log modelLog = new ChinaSoft.Model.Model_tb_MidSoft_log();
            ChinaSoft.BLL.BLL_tb_MidSoft_log bllLog = new ChinaSoft.BLL.BLL_tb_MidSoft_log();
            modelLog.userAccount = "";
            if (Session["UserAccount"] != null && Session["UserAccount"].ToString() != "")
                modelLog.userAccount = Session["UserAccount"].ToString();
            modelLog.userName = "";
            if (Session["UserName"] != null && Session["UserName"].ToString() != "")
                modelLog.userName = Session["UserName"].ToString();
            modelLog.description = "部门信息修改,ID=" + DepartMentId + ",DepartmentName=" + DepartmentName;
            modelLog.LogType = 2;
            modelLog.CreateTime = DateTime.Now;
            bllLog.Add(modelLog);
            #endregion
            Response.Write("<script>alert('成功！');top.window.parent.frames.item('workspace').location.reload();window.parent.$('#DivSysiframe').dialog(\"close\");</script>");
        }
    }
}